<cfcomponent output="false" extends="mxunit.framework.TestCase">
  <cffunction name="mailTest">
   <cfmail from="billshelton@comcast.net" to="billshelton@comcast.net"
           server="smtp.comcast.net" subject="test">
         test.
   </cfmail>
  </cffunction>
<cfscript>

function testConfigureLog4J(){
   logger = createObject('java' ,'org.apache.log4j.Logger').getLogger("cfesapi.test.Logger");
   path = "/home/billy/webapps/cfesapi/resources/log4j.xml";
   j = createObject('java' ,'org.apache.log4j.xml.DOMConfigurator');
  //jCongig = createObject("java","java.net.URL").init(path);
   j.configure(path);
   debug(logger);
   debug(logger.getName());
   debug(j);

   logger.debug("Here is some DEBUG");
   logger.info("Here is some INFO");
   logger.warn("Here is some WARN");
   logger.error("Here is some ERROR");
   logger.fatal("Here is some FATAL");
   cause = createObject("java",'java.lang.Throwable').init("you suck");
   e = createObject("java",'java.lang.Exception').init(cause);
   logger.info('test SECURITY_FAILURE with exception?',e);

}


 function testJavaLogger() {

   jlogger = logger.getJLogger();
   debug(jlogger);
   debug(jlogger.isDebugEnabled());
   debug(jlogger.ALL);
   debug(jlogger.EVENT_FAILURE);


  //type = logger.
  // jlogger.info(org.owasp.esapi.Logger$EventType, java.lang.String)
   //jlogger.info('', 'test');
   debug(logger);
 }


function configureOWASPLogger4Log4J() {
 loader = createObject('component' , 'cfesapi.org.owasp.esapi.ClassLoader').init();
 esapi = loader.create("org.owasp.esapi.ESAPI");
 //CREATE log4j factory (should ne ESAPI)
 log4j = loader.create("org.owasp.esapi.reference.Log4JLogFactory");

 debug(log4j);
 //set the logfactory to log4j
 esapi.setLogFactory(log4j);
 //set the path to config
 path = expandPath("/cfesapi/resources/log4j.xml");//default
 j = createObject('java' ,'org.apache.log4j.xml.DOMConfigurator');
 //configure the path
 j.configure(path);

 //get the logger
  logger = log4j.getLogger('cfesapi');
  debug(logger);

 logger.info(logger.EVENT_FAILURE,'Is this log4j?');

 cause = createObject("java",'java.lang.Throwable').init(":::TEST_LOG4J_IMPL:::");
 e = createObject("java",'java.lang.Exception').init(cause);
 logger.fatal(logger.SECURITY_FAILURE,'test SECURITY_FAILURE with exception with log4j.', e);
}

function testLog4JImpl() {
  createObject("java","java.lang.System").setProperty("org.owasp.esapi.resources" , "/home/billy/webapps/cfesapi/resources/.esapi");
  loader = createObject('component' , 'cfesapi.org.owasp.esapi.ClassLoader').init();
  config = loader.create("org.owasp.esapi.ESAPI").securityConfiguration();
  //config.setResourceDirectory("/home/billy/webapps/cfesapi/resources");
  debug(config);
  encoder = loader.create("org.owasp.esapi.ESAPI").encoder();
  logger = loader.create("org.owasp.esapi.ESAPI").getLogger('cfesapi.test.Logger');
  logger.setLevel(logger.ALL);

   path = "/home/billy/webapps/cfesapi/resources/log4j.xml";
   j = createObject('java' ,'org.apache.log4j.xml.DOMConfigurator');
  //jCongig = createObject("java","java.net.URL").init(path);
   j.configure(path);

  debug("where is all this logged? Looks like STDOUT");
  debug(logger);
  cause = createObject("java",'java.lang.Throwable').init(":::TEST_LOG4J_IMPL:::");
  e = createObject("java",'java.lang.Exception').init(cause);
  logger.info(logger.EVENT_FAILURE,'test failure');
  logger.debug(logger.EVENT_SUCCESS,'test debug log');
  logger.fatal(logger.EVENT_FAILURE,'test FAILURE log');
  logger.error(logger.EVENT_FAILURE,'test error log');
  logger.info(logger.SECURITY_FAILURE,'test SECURITY_FAILURE with exception?', e);
  logger.fatal(logger.SECURITY_FAILURE,'test SECURITY_FAILURE with exception?', e);
 }



  function testSetLevel(){
   config = esapi.securityConfiguration() ;
   //debug(config.getLogLevel());

   logger = esapi.logger('mylogger') ;
   //debug(logger.getLevel());
   logger.setLevel('WARN');
   assert('WARN'==logger.getLevel());
  }



  function setUp(){
      esapi = createObject('component', 'cfesapi.org.owasp.esapi.ESAPI').init();
      logger = createObject('component', 'cfesapi.org.owasp.esapi.Logger').init() ;
  }

  function tearDown(){

  }


</cfscript>
</cfcomponent>